import os
import sys

script_path = os.path.abspath(__file__)
script_dir = os.path.dirname(script_path)
sys.path.insert(0, script_dir)
from typing import Any

from baseClass.bullet import *
from baseClass.amount import *
from baseClass.zombie import *
from baseClass.other import *
from baseClass.card import *
from pygame import font, event


class pea_shooter_card(Card):
    def __init__(
        self,
        initSchedule: int,
        index: int = 0,
        schedule_speed: int = 10,
        sunNum: int = None,
    ) -> None:
        if not sunNum:
            sunNum = 100
        super().__init__(
            initSchedule, schedule_speed, sunNum, "../../PVZ素材/植物/豌豆射手.gif"
        )
        self.index = index
        self.prospect = pygame.Surface(
            (self.rect.width, self.rect.height), pygame.SRCALPHA
        )
        self.prospect.fill((0, 0, 0, 100), self.prospect.get_rect())
        self.prospect_rect = self.prospect.get_rect()
        self.last_update_time = pygame.time.get_ticks()
        self.sunnumStr = font.Font(None, 16).render(str(self.sunNum), True, (0, 0, 0))
        self.srect = self.sunnumStr.get_rect()
        self.srect.left += 10

    def update(self, *args: Any, **kwargs: Any) -> None:
        srect = self.sunnumStr.get_rect()
        srect.bottom = self.rect.bottom - 5
        self.image.blit(
            self.sunnumStr,
            srect,
        )
        if self.schedule < 60:
            current_time = pygame.time.get_ticks()
            if current_time - self.last_update_time > 1000:
                self.image.blit(
                    self.img_copy,
                    self.img_copy_rect,
                )
                self.image.blit(
                    self.prospect,
                    self.img_copy_rect,
                )

                self.schedule += self.schedule_speed
                self.last_update_time = current_time

    def mouse_event(self, event: event.Event) -> None:
        """鼠标事件"""
        if self.schedule == 100 and self.rect.collidepoint(event.pos):
            self.follow_mouse = True
